""" Models/Orders Model """

from masoniteorm.models import Model
from masoniteorm.scopes import scope
from masoniteorm.relationships import has_one, has_many


class Orders(Model):
    """Models/Orders Model"""
    # __appends__ = ['not_used_count', 'is_being_used']
    # 未使用的数量
    # def get_not_used_count_attribute(self):
    #     return self.order_item.scope_quantity - self.order_used_count

    # 判断使用状态
    # def get_is_being_used_attribute(self):
    #     return

    @scope
    def order_paid(self, query, uid: int):
        return query.where('uid', uid).where('status', 'paid')

    @has_one('order_id', 'id')
    def order_item(self):
        from modules.admin.models.OrderItems import OrderItems
        return OrderItems

    @has_one('order_id', 'id')
    def order_used(self):
        from modules.admin.models.OrderUsed import OrderUsed
        return OrderUsed

